﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VicMessenger.DB;

namespace VicMessenger.DAL
{
    public class ContactDAL
    {
        public static List<proc_Contact_SelectResult> GetContact(long? prmContactID, int? prmCampaignID)
        {
            try
            {
                using (ContackDBDataContext db = new ContackDBDataContext())
                {
                    return db.proc_Contact_Select(prmContactID, prmCampaignID).ToList();
                }
            }
            catch (Exception)
            {
                return null;
            }
        }

        public static List<proc_Contact_CustomPagingResult> GetContactCustomPaging(int? prmCampaignID, int? prmPageIndex, int? prmMaxRow, out int? prmTotalRows)
        {
            try
            {
                using (ContackDBDataContext db = new ContackDBDataContext())
                {
                    prmTotalRows = 0;
                    return db.proc_Contact_CustomPaging(prmCampaignID, prmPageIndex, prmMaxRow, ref prmTotalRows).ToList();
                }
            }
            catch (Exception)
            {
                prmTotalRows = 0;
                return null;
            }
        }

        public static long? InsertUpdateContact(proc_Contact_CustomPagingResult prmContact)
        {
            try
            {
                long? retContactID = 0;
                using (ContackDBDataContext db = new ContackDBDataContext())
                {
                    db.proc_Contact_InsertUpdate(prmContact.ContactID,
                                                        prmContact.CampaignID,
                                                        prmContact.Email,
                                                        prmContact.Status,
                                                        ref retContactID);



                    return retContactID;
                }
            }
            catch (Exception)
            {
                return 0;
            }
        }

        public static int DeleteContact(long prmContactId)
        {
            try
            {
                using (ContackDBDataContext db = new ContackDBDataContext())
                {
                    return db.proc_Contact_Delete(prmContactId);
                }
            }
            catch (Exception)
            {
                return 0;
            }
        }

    }
}
